$(function() {
	//WASP_WIDGET.initializeSelectStyle();
	WASP_WIDGET.triggerDateStyleWithYMD("#expectPayDate");
	WASP_WIDGET.triggerDateStyleWithYMD("#bnsDate");
	
	//WASP_WIDGET.triggerDateRangeStyle("expectPayDate");
	
	fmtNum152('expectPayAmount');
	fmtNum152('bnsAmt');
});
function submitAddForm() {
	if(!validateFeePlan()){
		return false;
	}
	
	var expectPayAmount=replaceSpecialStr($('#expectPayAmount').val());
	var bnsAmt=replaceSpecialStr($('#bnsAmt').val());
	$('#expectPayAmount').val(expectPayAmount);
	$('#bnsAmt').val(bnsAmt);
	
	SubmitAndPreventSecond("addForm",function(){
		//document.addForm.action = "feeOrYieldInfoUpdate.do";
	});
}

//重算时验证费用
function validateFeePlan() {
	var expectPayDate = $('#expectPayDate').val();
	if (null == expectPayDate || expectPayDate == "") {
		ctools.alert("预计支付日不能为空!","","error");
		return false;
	}
	var expectPayAmount = $('#expectPayAmount').val();
	if (null == expectPayAmount || expectPayAmount == "") {
		ctools.alert("预计付款金额不能为空!","","error");
		return false;
	}
	var bnsDate = $('#bnsDate').val();
	var bnsAmt = $('#bnsAmt').val();
	if((bnsDate != "" && bnsAmt == "")
			|| (bnsDate == "" && bnsAmt != "")){
		    ctools.alert("实际支付日和实际支付金额同时必填或同时为空!","","error");
			//$("#" + id + "_bnsDate").focus();
			return false;
	}
	if(bnsDate!=''){
		 if (expectPayDate > bnsDate) {
			 toastr.error("支付列表中的预计支付日不能大于实际支付日");
	         return false;
		 }
	}
	
	var type = $('#type').val();
	var cashFlowsDate = $('#cashFlowsDate').val();
	if(type == 'Z'){
		if(cashFlowsDate != expectPayDate){
			
			var falg=true;
			
			$.ajax({
				url : path+"vReturnPlan.do",
				data : {
					'subPrdCode':$('#feeId').val(),
					'cashFlowsDate':expectPayDate
				},
				dataType : "json",
				cache : false,
				async: false,
				error : function(textStatus, errorThrown) {
					ctools.alert("系统ajax交互错误: ",'',"warning");
				},
				success : function(data) {
					if(data > 0){
						falg=false;
					}
				}
			});
			
			if(!falg){
				toastr.error("当类型为客户本金时，预计支付日不能和历史数据相同！");
		        return false;
			}
			
		}
	}
	
	return true;	
}

//去掉逗号
function replaceSpecialStr(str){
	if(str !="" && str!=null){
		str = str.replace(/,/g,'');
	}
	return str;
}